package com.scy.java.object.StringDemo;
import java.util.Scanner;
//金额转化
public class StringDemo2 {
    public static void main(String[] args) {
        //键盘录入金额
        System.out.println("请输入金额：");
        Scanner scanner = new Scanner(System.in);
        int money = scanner.nextInt();
        //定义一个变量，用来表示钱的大写
        String moneyStr = "";
        //得到money中的每一个数字，再转为213中文
        while (true){
            //从右边往左获取数据，右侧是个位
            int geNum = money%10;
            String strNum = getStrNum(geNum);
            moneyStr = strNum +moneyStr ;
            System.out.println(moneyStr);

            //去掉刚刚获取的数据
            money = money / 10;
            if (money == 0){//当money==0时跳出循环
                break;
            }

        }

        //在前面补0，补齐七位
        int len = 7-moneyStr.length();
        for (int i = 0; i < len; i++) {
            moneyStr = "零" +moneyStr;
        }
        System.out.println(moneyStr);
        //插入单位
        //定义一个数组
        String[] s2 = {"佰", "拾", "万", "仟", "佰", "拾","元" };
        String result = "";
        for (int i = 0; i < moneyStr.length(); i++) {
            //获取moneyStr的每一个字符
            char c = moneyStr.charAt(i);
            result=result+c+s2[i];

        }
        //打印结果
        System.out.println(result);

    }

    //把数字抓化成大写的中文
    private static String getStrNum(int geNum) {
        //定义字符串数组
        String[] arr = {"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};

        return arr[geNum];

    }
    //-------------------------------------------------------------------------------------
//    public static void main(String[] args) {
//        System.out.println("请输入一串数字：");
//        String sNext = new Scanner(System.in).next();
//        System.out.println("toChinese："+toChinese(sNext));
//
//    }
//    public static String toChinese(String str) {
//        String[] s1 = { "零", "一", "二", "三", "四", "五", "六", "七", "八", "九" };
//        String[] s2 = { "十", "百", "千", "万", "十", "百", "千", "亿", "十", "百", "千" };
//        String result = "";
//        for (int i = 0; i < str.length(); i++) {
//            int num= str.charAt(i)-'0';
//            if (i != str.length() - 1 && num != 0) {
//                result += s1[num] + s2[str.length() - 2 - i];
//            } else {
//                result += s1[num];
//            }
//        }
//        return result;
//    }

}
